<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>外间距重叠</title>
    <style>
      .box {
        width: 100px;
        height: 100px;
      }
      #d1 {
        background-color: blue;
        margin-bottom: 20px;
      }
      #d2 {
        background-color: red;
        margin-top: 10px;
      }
      #d3 {
        background-color: black;
        margin-top: 20px;
        position: relative;
      }
      #d4 {
        width: 50px;
        height: 50px;
        background-color: pink;
        margin-top: 50px;
        position: absolute;
      }

      body {
        margin: 0;
      }
    </style>
  </head>
  <body>
    <div class="box" id="d1"></div>
    <div class="box" id="d2"></div>
    <div class="box" id="d3"><div id="d4"></div></div>
  </body>
</html>
